//
//  EmotitionPackage.swift
//  表情栏
//
//  Created by Dengdwd on 15/10/21.
//  Copyright © 2015年 dwd. All rights reserved.
//

import UIKit
//
class EmotitionPackage: NSObject {

    var id:String?
    var group_name_cn:String?
    lazy var emoticons = [Emotition]()
    
    init(dict:[String:AnyObject]) {
        super.init()
        id = dict["id"] as? String
        group_name_cn = dict["group_name_cn"] as? String
        if let array = dict["emoticons"] as? [[String:String]] {
            var index = 0
            for var d in array {
                if let imagePath = d["png"]{
                d["png"] = id! + "/" + imagePath
                }

                let emotition = Emotition(dict:d)
                emoticons.append(emotition)
                
                index++
                if index == 20 {
                    emoticons.append(Emotition(isRemove: true))
                    index = 0
                }
            } 
        }
        
        let count = emoticons.count % 21

        if count == 0 && emoticons.count > 0 {
        return
        }
        for _ in count ..< 20 {
        emoticons.append(Emotition(isEmpty: true))
        }
        emoticons.append(Emotition(isRemove: true))
    }
    override var description:String {
        let keys = ["id","group_name_cn","emoticons"]
        return dictionaryWithValuesForKeys(keys).description
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
}
